home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbbresd.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  5.1 KB  |  206 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.57.57;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbbresd.c,v 1.3 89/11/08 17:12:27 keith Exp $ */
  50. #include "X.h"
  51. #include "misc.h"
  52. #include "mfb.h"
  53. #include "maskbits.h"
  54.  
  55. /* Dashed bresenham line */
  56.  
  57. #define StepDash\
  58.     if (!--dashRemaining) { \
  59.     if (++ dashIndex == numInDashList) \
  60.         dashIndex = 0; \
  61.     dashRemaining = pDash[dashIndex]; \
  62.     rop = fgrop; \
  63.     if (dashIndex & 1) \
  64.         rop = bgrop; \
  65.     }
  66.  
  67. mfbBresD(fgrop, bgrop,
  68.      pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
  69.      addrl, nlwidth,
  70.      signdx, signdy, axis, x1, y1, e, e1, e2, len)
  71. int fgrop, bgrop;
  72. int *pdashIndex;    /* current dash */
  73. unsigned char *pDash;    /* dash list */
  74. int numInDashList;    /* total length of dash list */
  75. int *pdashOffset;    /* offset into current dash */
  76. int isDoubleDash;
  77. int *addrl;        /* pointer to base of bitmap */
  78. int nlwidth;        /* width in longwords of bitmap */
  79. int signdx, signdy;    /* signs of directions */
  80. int axis;        /* major axis (Y_AXIS or X_AXIS) */
  81. int x1, y1;        /* initial point */
  82. register int e;        /* error accumulator */
  83. register int e1;    /* bresenham increments */
  84. int e2;
  85. int len;        /* length of line */
  86. {
  87.     register int yinc;    /* increment to next scanline, in bytes */
  88.     register unsigned char *addrb;
  89.     register int e3 = e2-e1;
  90.     register unsigned long bit;
  91.     unsigned int leftbit = mask[0]; /* leftmost bit to process in new word */
  92.     unsigned int rightbit = mask[31]; /* rightmost bit to process in new word */
  93.     int dashIndex;
  94.     int dashOffset;
  95.     int dashRemaining;
  96.     int    rop;
  97.  
  98.     dashOffset = *pdashOffset;
  99.     dashIndex = *pdashIndex;
  100.     dashRemaining = pDash[dashIndex] - dashOffset;
  101.     rop = fgrop;
  102.     if (!isDoubleDash)
  103.     bgrop = -1;
  104.     if (dashIndex & 1)
  105.     rop = bgrop;
  106.  
  107.     /* point to longword containing first point */
  108.     addrb = (unsigned char *)(addrl + (y1 * nlwidth) + (x1 >> 5));
  109.     yinc = signdy * nlwidth * 4;                /* 4 == sizeof(int) */
  110.     e = e-e1;            /* to make looping easier */
  111.     bit = mask[x1 & 31];
  112.     if (axis == X_AXIS)
  113.     {
  114.     if (signdx > 0)
  115.     {
  116.         while(len--)
  117.         { 
  118.         if (rop == RROP_BLACK)
  119.             *(unsigned long *)addrb &= ~bit;
  120.         else if (rop == RROP_WHITE)
  121.             *(unsigned long *)addrb |= bit;
  122.         else if (rop == RROP_INVERT)
  123.             *(unsigned long *)addrb ^= bit;
  124.         e += e1;
  125.         if (e >= 0)
  126.         {
  127.             addrb += yinc;
  128.             e += e3;
  129.         }
  130.         bit = SCRRIGHT(bit,1);
  131.         if (!bit) { bit = leftbit;addrb += 4; }
  132.         StepDash
  133.         }
  134.     }
  135.     else
  136.     {
  137.         while(len--)
  138.         { 
  139.         if (rop == RROP_BLACK)
  140.             *(unsigned long *)addrb &= ~bit;
  141.         else if (rop == RROP_WHITE)
  142.             *(unsigned long *)addrb |= bit;
  143.         else if (rop == RROP_INVERT)
  144.             *(unsigned long *)addrb ^= bit;
  145.         e += e1;
  146.         if (e >= 0)
  147.         {
  148.             addrb += yinc;
  149.             e += e3;
  150.         }
  151.         bit = SCRLEFT(bit,1);
  152.         if (!bit) { bit = rightbit;addrb -= 4; }
  153.         StepDash
  154.         }
  155.     }
  156.     } /* if X_AXIS */
  157.     else
  158.     {
  159.     if (signdx > 0)
  160.     {
  161.         while(len--)
  162.         {
  163.         if (rop == RROP_BLACK)
  164.             *(unsigned long *)addrb &= ~bit;
  165.         else if (rop == RROP_WHITE)
  166.             *(unsigned long *)addrb |= bit;
  167.         else if (rop == RROP_INVERT)
  168.             *(unsigned long *)addrb ^= bit;
  169.         e += e1;
  170.         if (e >= 0)
  171.         {
  172.             bit = SCRRIGHT(bit,1);
  173.             if (!bit) { bit = leftbit;addrb += 4; }
  174.             e += e3;
  175.         }
  176.         addrb += yinc;
  177.         StepDash
  178.         }
  179.     }
  180.     else
  181.     {
  182.         while(len--)
  183.         {
  184.         if (rop == RROP_BLACK)
  185.             *(unsigned long *)addrb &= ~bit;
  186.         else if (rop == RROP_WHITE)
  187.             *(unsigned long *)addrb |= bit;
  188.         else if (rop == RROP_INVERT)
  189.             *(unsigned long *)addrb ^= bit;
  190.         e += e1;
  191.         if (e >= 0)
  192.         {
  193.             bit = SCRLEFT(bit,1);
  194.             if (!bit) { bit = rightbit;addrb -= 4; }
  195.             e += e3;
  196.         }
  197.         addrb += yinc;
  198.         StepDash
  199.         }
  200.     }
  201.     } /* else Y_AXIS */
  202.     *pdashIndex = dashIndex;
  203.     *pdashOffset = pDash[dashIndex] - dashRemaining;
  204. @
  205.